package com.example.service.impl;

import com.example.mapper.DeviceMapper;
import com.example.mapper.OutputAllMapper;
import com.example.pojo.Baobiao;
import com.example.pojo.Device;
import com.example.pojo.PageBean;
import com.example.service.DeviceService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private OutputAllMapper outputAllMapper;
    @Override
    public PageBean page(Integer page, Integer pageSize, String deviceid, String note) {
        Long count = deviceMapper.count(deviceid,note);//总数返回
        Integer start=(page-1)*pageSize;//计算起始位置
        List<Device> devices = deviceMapper.page(start, pageSize,deviceid,note);//该页记录数返回

        PageBean pageBean = new PageBean(count, devices);
        return pageBean;
    }

    @Override
    public void add(Device device) {
        deviceMapper.add(device);

    }

    @Override
    public void update(Device device) {
        device.setDevdate(LocalDate.now());
        outputAllMapper.add("维修"+device.getDeviceid()+"问题为"+device.getPro()+device.getNote(),device.getPrice(),LocalDate.now());
        System.out.println("维修"+device.getDeviceid()+"问题为"+device.getPro()+device.getNote());
        deviceMapper.update(device);
        deviceMapper.delete(device.getId());
    }
}
